import 'package:flutter/material.dart';

class TestInput extends StatefulWidget {
  @override
  _TestInputState createState() => _TestInputState();
}

class _TestInputState extends State<TestInput> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Form Test"),
      ),
      body: Padding(
        padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
        child: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              Container(
                decoration: BoxDecoration(
                    color: Color(0xFFeeeeee),
                    borderRadius: BorderRadius.all(Radius.circular(5)),
                    border: Border.all(
                        color: Colors.blue,
                        width: 1,
                        style: BorderStyle.solid)),
                child: TextFormField(
                    scrollPadding: EdgeInsets.all(5),
                    cursorColor: Colors.redAccent,
                    autofocus: true,
                    maxLength: 200,
                    maxLines: 1,
                    decoration: InputDecoration(
                      border: InputBorder.none,
                      hintText: "用户名或邮箱",
                    ),
                    // 校验用户名
                    validator: (v) {
                      return v.trim().length > 0 ? null : "用户名不能为空";
                    }),
              ),
              TextFormField(
                  decoration: InputDecoration(
                      labelText: "密码",
                      hintText: "您的登录密码",
                      icon: Image.asset(
                        "assets/images/avatar.png",
                        width: 15,
                      )),
                  obscureText: true,
                  //校验密码
                  validator: (v) {
                    return v.trim().length > 5 ? null : "密码不能少于6位";
                  }),
            ],
          ),
        ),
      ),
    );
  }
}
